package test.com.sms.selenium.singlepoint.util;

import java.util.Set;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;

public class SpSROEditPageUtil extends SeleniumPageUtil {

	public final static By SE_SELECT_TARN_TYPE = By.id("ctl44_cboTransactionType");
	public final static By SE_SELECT_COST_LOC = By.id("ctl44_cboPaymentType");
	public final static By SE_SELECT_CODE = By.id("ctl44_cboCode");
	
	// 1 sign that selecting 'Customer Ship' as Code
	// 2 sign that selecting 'Customer Return' as Code
	public final static By SE_INPUT_ITEM_1 = By.id("ctl44_txtItem");
	public final static By SE_INPUT_ITEM_2 = By.id("ctl44_txtItem2");
	public final static By SE_SELECT_WAREHOUSE_1 = By.id("ctl44_cdoWarehouse2");
	public final static By SE_SELECT_WAREHOUSE_2 = By.id("ctl44_cdoWarehouse2");
	public final static By SE_OPTION_WAREHOUSE = By.xpath("//*[@id='ctl44_cdoWarehouse2']/option[2]");
	public final static By SE_INPUT_SERIAL_NUMBER = By.id("ctl44_txtSerialNumber2");
	public final static By SE_CHECKBOX_SERIAL_NUMBER = By.xpath("//*[@id='ctl44_PnlSerialNumberList']/table/tbody/tr[2]/td[1]/input[1]");
	public final static By SE_TD_SERIAL_NUMBER = By.xpath("//*[@id='ctl44_PnlSerialNumberList']/table/tbody/tr[2]/td[2]");
	
	public final static By SE_CAL_DATE = By.id("ctl44_imgLaborCalc");

	public final static By SE_START_TIME = By.id("ctl44_txtLaborCalcStart");
	public final static By SE_END_TIME = By.id("ctl44_txtLaborCalcEnd");
	public final static By SE_BTN_SAVE = By.id("ctl44_btnLaborCalcSave");
	public final static By SE_BTN_CANCEL = By.id("ctl44_btnLaborCalcClose");

	public final static By SE_INPUT_QUANTITY = By.id("ctl44_txtQuantity");
	public final static By SE_SELECT_BILL_CODE = By.id("ctl44_cboBillCode");
	public final static By SE_INPUT_NOTE = By.id("ctl44_txtNotes");
	public final static By SE_BTN_CREATE = By.id("ctl44_btnFormSubmit");
	public final static By SE_SPAN_TRAN_LIST = By.id("ctl44_lblTransactionList");
	public final static By SE_BTN_POST = By.id("POST_BUTTON_LABOR");
	public final static By SE_INPUT_OVERTIME = By.id("ctl44_txtHrsOvertime");
	public final static By SE_BTN_CONTINIUE = By.id("ctl44_btnPostContinue");
	
	public final static By SE_DIV_CODE_LIST_1 = By.id("ctl44_aceItem_completionListElem");
	public final static By SE_DIV_CODE_LIST_2 = By.id("ctl44_aceItem2_completionListElem");
	
	public static void enterSroDetailsPage(WebElement element){
		SeleniumUtil.waitForFixedMilliseconds(3000);
		Set<String> before = SeleniumUtil.getWindowHandles();
		SeleniumUtil.click(element);
		
		// if browser prompt out a new window, switch to it
		SeleniumUtil.switchToPromptedWindow(before, SeleniumUtil.getWindowHandles());
		SeleniumUtil.selectDefaultContent();
		SeleniumUtil.waitOnElements(new By[]{
				SE_SELECT_TARN_TYPE,SE_SELECT_BILL_CODE,SE_INPUT_NOTE
		});
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_SELECT_TARN_TYPE));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_SELECT_BILL_CODE));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_INPUT_NOTE));
	}
	
	public static void waitForPageToLoad() {
		SeleniumUtil.selectDefaultContent();
		SeleniumUtil.selectFrame(SpHomePageUtil.HOME_FRAME_CONTENT_NAME);
		SeleniumUtil.waitOnElements(new By[]{
				SE_SELECT_TARN_TYPE, SE_SELECT_COST_LOC, SE_SELECT_CODE, SE_CAL_DATE, SE_START_TIME, SE_END_TIME,
				SE_BTN_SAVE, SE_BTN_CANCEL, SE_SELECT_BILL_CODE, SE_BTN_POST
		});
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_SELECT_TARN_TYPE));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_SELECT_COST_LOC));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_SELECT_CODE));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_START_TIME));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_END_TIME));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_BTN_SAVE));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_BTN_CANCEL));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_SELECT_BILL_CODE));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SE_BTN_POST));
	}
}
